package qq.service;

import org.apache.ibatis.session.SqlSession;
import qq.bean.User;
import qq.mapper.UserMapper;
import qq.tool.MybatisTool;

import java.io.IOException;
import java.util.List;

public class UserSevice {
    public static void declinePoint(long qq,int n) throws IOException {
        SqlSession sqlSession = MybatisTool.getSqlSession();
        UserMapper userMapper =sqlSession.getMapper(UserMapper.class);
        userMapper.declinePoint(qq,n);
        sqlSession.commit();
        sqlSession.close();
    }

    public static void addPoint(long qq,int n) throws IOException {
        SqlSession sqlSession = MybatisTool.getSqlSession();
        UserMapper userMapper =sqlSession.getMapper(UserMapper.class);
        userMapper.addPoint(qq,n);
        sqlSession.commit();
        sqlSession.close();
    }

    public static User getUser(long qq) throws IOException {
        SqlSession sqlSession = MybatisTool.getSqlSession();
        UserMapper userMapper =sqlSession.getMapper(UserMapper.class);
        return userMapper.getUser(qq);
    }

    public static List<User> getRank() throws IOException {
        SqlSession sqlSession = MybatisTool.getSqlSession();
        UserMapper userMapper =sqlSession.getMapper(UserMapper.class);
        return userMapper.rank();
    }
}
